import { Message } from 'element-ui';
import selectionChang from './selectionChang'
export default{
  mixins: [selectionChang],
  data() {
    return {
    }
  },
  methods: {
    doForbidden(userids, status, msg) {
      this.$confirm(msg, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.batchBlockFun()({
          users: userids,
          status: status
        }, res => {
          this.$message({
            type: 'success',
            message: res.message
          });
          this.getList();
        }, err => { console.log(err) })
      }).catch((err) => {
        console.error(err)
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    onMulForbidden() {
      if(this.multipleSelection.length == 0) {
        return Message.warning('请选择要处理用户');
      }
      let userids = this.multipleSelection.map((v) => {
        return v.userid;
      })
      this.doForbidden(userids, 2, '确定批量封禁用户？');
    },
    onMulEnable() {
      if(this.multipleSelection.length == 0) {
        return Message.warning('请选择要处理用户');
      }
      let userids = this.multipleSelection.map((v) => {
        return v.userid;
      })
      this.doForbidden(userids, 1, '确定批量启用用户？');
    },
    onForbidden(row) {
      // debugger
      let ope = row.status == 1 ? '封禁' : '启用';
      let status = row.status == 1 ? 2 : 1;
      this.doForbidden([row.userid], status, `确定${ope}用户${row.username}?`);
    }
  }
}